
//
//  HelpViewController.m
//  DaJiang
//
//  Created by sally on 16/10/5.
//  Copyright © 2016年 jiniu. All rights reserved.
//

#import "AboutWeViewController.h"
#import "AdviceViewController.h"
#import "CellManager.h"
#import "HelpViewController.h"

@interface HelpViewController ()

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *tableData;
@property (strong, nonatomic) NSMutableArray *detailTextData;

@end

@implementation HelpViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  [self initControl];
  [self initData];
}

#pragma mark 初始化控件
- (void)initControl {
  if (self.helpType == HelpType_Service) { //联系客服
    self.title = @"联系客服";
  } else {
    self.title = @"帮助";
  }

  [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}

#pragma mark 初始化数据
- (void)initData {
  self.tableData = [NSMutableArray array];
  if (self.helpType == HelpType_Service) { //联系客服
    self.detailTextData = [NSMutableArray array];
    [self.tableData addObject:@[ @"邮箱", @"联系客服" ]];
    [self.detailTextData addObject:@[ @"service@dajiang.com", @"4000-666-88（工作日10:00-19:00）" ]];

  } else {
    [self.tableData addObject:@[ @"意见反馈", @"联系客服", @"关于我们" ]];
  }
}

#pragma mark - TableView data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  return self.tableData.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  return [[self.tableData objectAtIndex:section] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  return 0.1; //section头部高度
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  UITableViewCell *cell;

  if (self.helpType == HelpType_Service) { //联系客服
    //主副标题形式
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"];

    //副标题
    [CellManager configCellDetailText:cell];
    cell.detailTextLabel.text = [[self.detailTextData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

    if (indexPath.row == 1) { //工作日的字体设10
      NSString *detailText = [[self.detailTextData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
      NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:detailText];
      [attrStr addAttribute:NSFontAttributeName value:GFontWithSize(GXSmallFontSize) range:NSMakeRange(11, detailText.length - 11)];
      cell.detailTextLabel.attributedText = attrStr;
    }

    //列表项点击性
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

  } else {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

    //右箭头
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  }

  //主标题
  [CellManager configCellNormalText:cell];
  cell.textLabel.text = [[self.tableData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

  return cell;
}

#pragma mark TableView delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  [tableView deselectRowAtIndexPath:indexPath animated:YES]; //返回后选中状态消失
  if (self.helpType == HelpType_Main) {

    if (indexPath.row == 0) { //意见反馈
      AdviceViewController *vc = [[AdviceViewController alloc] init];
      [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 1) { //联系客服
      HelpViewController *vc = [[HelpViewController alloc] init];
      vc.helpType = HelpType_Service;
      [self.navigationController pushViewController:vc animated:YES];
    } else if (indexPath.row == 2) { //关于我们
      AboutWeViewController *vc = [[AboutWeViewController alloc] init];
      [self.navigationController pushViewController:vc animated:YES];
    }
  }
}

@end
